package demo;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.slf4j.Logger;

@RunWith(PowerMockRunner.class)
@PrepareForTest({BaseLogger.class})
public class ServiceDemoTest {

    @InjectMocks
    ServiceDemo serviceDemo;

    @Mock
    BaseLogger baseLogger;

    @Mock
    Logger logger;

    @Before
    public void beforeClass(){
        MockitoAnnotations.initMocks(this);
        PowerMockito.mockStatic(BaseLogger.class);
    }

    @Test
    public void busi_2_test(){
        PowerMockito.when(BaseLogger.getName()).thenAnswer(e -> "asd");
        PowerMockito.when(BaseLogger.getLogger()).thenAnswer(e -> logger);
        PowerMockito.when(logger.isDebugEnabled()).thenReturn(Boolean.TRUE);
        serviceDemo.busi();
    }

    @Test
    public void busi_test(){

        PowerMockito.when(BaseLogger.getName())
                .thenAnswer(new Answer<String>() {
            @Override
            public String answer(InvocationOnMock invocationOnMock) throws Throwable {
                return "asd";
            }
        });

        PowerMockito.when(BaseLogger.getLogger()).thenAnswer(new Answer<Logger>() {
            @Override
            public Logger answer(InvocationOnMock invocationOnMock) throws Throwable {
                return logger;
            }
        });

        PowerMockito.when(logger.isDebugEnabled()).thenReturn(Boolean.TRUE);

        serviceDemo.busi();
    }

}
